﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeGenerator;
using JUtil;
namespace MasterViewGeneratorConsole
{
    class Program
    {
        #region CategoriesSetting
        private static CodeGenSetting CategoriesSetting
        {
            get
            {
                return new CodeGenSetting
                {
                    DbSetting = new DbSetting
                    {
                        DbProvider = DbProvider.OleDb,
                        ConnectionString = @"Provider=SQLOLEDB.1;Password=sapass;Persist Security Info=True;User ID=sa;Initial Catalog=Northwind;Data Source=JELLY\SQLEXPRESS",
                        DatabaseType = DatabaseType.SqlServer
                    },

                    CSharpFileSetting = new CSharpFileSetting
                    {
                        NAMESPACE = "DemoCodeGen",
                        BLL_CLASS = "BLLCategories",
                        DAL_CLASS = "Categories",
                        ASPX_CLASS = "DemoCategories"
                    },

                    RelatedSql = new RelatedSql
                    {
                        GetOrderBy = "order by CategoryID",
                        GetSelectSQLNoOrderBy = "select * from Categories",
                        GetSelectDetailsVwSQL = "select * from Categories where CategoryID = {0}",
                        GetInsertSQL = "insert into Categories (CategoryID, CategoryName, Description, Picture) values (?,?,?,?)",
                        GetUpdateSQL = "update Categories set CategoryID=?, CategoryName=?, Description=?, Picture=? where (CategoryID=?) and (1=1)",
                        GetDeleteSQL = "delete from Categories where (CategoryID=@CategoryID)"
                    },

                    ExportDirectorySetting = new ExportDirectorySetting
                    {
                        SqlFile = @"E:\GoogleProjectHosting\jelly-util-codegen\MasterViewGeneratorSite\App_Data\SQL",
                        DalFile = @"E:\GoogleProjectHosting\jelly-util-codegen\MasterViewGeneratorSite\App_Code\DAL",
                        BllFile = @"E:\GoogleProjectHosting\jelly-util-codegen\MasterViewGeneratorSite\App_Code\BLL",
                        AspxCsFile = @"E:\GoogleProjectHosting\jelly-util-codegen\MasterViewGeneratorSite"
                    }
                };
            }
        }
        #endregion
        #region EmployeesSetting
        private static CodeGenSetting EmployeesSetting
        {
            get
            {
                return new CodeGenSetting
                {
                    DbSetting = new DbSetting
                    {
                        DbProvider = DbProvider.OleDb,
                        ConnectionString = @"Provider=SQLOLEDB.1;Password=sapass;Persist Security Info=True;User ID=sa;Initial Catalog=Northwind;Data Source=JELLY\SQLEXPRESS",
                        DatabaseType = DatabaseType.SqlServer
                    },

                    CSharpFileSetting = new CSharpFileSetting
                    {
                        NAMESPACE = "DemoCodeGen",
                        BLL_CLASS = "BLLEmployees",
                        DAL_CLASS = "Employees",
                        ASPX_CLASS = "DemoEmployees"
                    },

                    RelatedSql = new RelatedSql
                    {
                        GetOrderBy = "order by EmployeeID",
                        GetSelectSQLNoOrderBy = "select * from Employees",
                        GetSelectDetailsVwSQL = "select * from Employees where EmployeeID = {0}",
                        GetInsertSQL = "insert into Employees (EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
                        GetUpdateSQL = "update Employees set   EmployeeID=?,LastName=?,FirstName=?,Title=?,TitleOfCourtesy=?,BirthDate=?,HireDate=?,Address=?,City=?,Region=?,PostalCode=?,Country=?,HomePhone=?,Extension=?,Photo=?,Notes=?,ReportsTo=?,PhotoPath=?where (EmployeeID=?) and (1=1)",
                        GetDeleteSQL = "delete from Employees where (EmployeeID=@EmployeeID)"
                    },

                    ExportDirectorySetting = new ExportDirectorySetting
                    {
                        SqlFile = @"E:\GoogleProjectHosting\jelly-util-codegen\MasterViewGeneratorSite\App_Data\SQL",
                        DalFile = @"E:\GoogleProjectHosting\jelly-util-codegen\MasterViewGeneratorSite\App_Code\DAL",
                        BllFile = @"E:\GoogleProjectHosting\jelly-util-codegen\MasterViewGeneratorSite\App_Code\BLL",
                        AspxCsFile = @"E:\GoogleProjectHosting\jelly-util-codegen\MasterViewGeneratorSite"
                    }
                };
            }
        }
        #endregion

        #region RunMasterViewGenerator
        static void RunMasterViewGenerator(CodeGenSetting CodeGenSetting)
        {
            try
            {
                MasterViewGenerator generator = new MasterViewGenerator(CodeGenSetting);
                generator.Export();
            }
            catch (Exception ex)
            {
                Log.ReportError(ex);
            }
        }
        #endregion

        static void Main(string[] args)
        {
            RunMasterViewGenerator(EmployeesSetting);
            RunMasterViewGenerator(CategoriesSetting);
        }
    }
}
